package com.hiultra.archive.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.hiultra.archive.domain.ArchiveBoxInoutdetail;
import com.hiultra.archive.service.IArchiveBoxInoutdetailService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hiultra.common.annotation.Log;
import com.hiultra.common.core.controller.BaseController;
import com.hiultra.common.core.domain.AjaxResult;
import com.hiultra.common.enums.BusinessType;
import com.hiultra.archive.domain.ArchiveBoxInoutRecords;
import com.hiultra.archive.service.IArchiveBoxInoutRecordsService;
import com.hiultra.common.utils.poi.ExcelUtil;
import com.hiultra.common.core.page.TableDataInfo;

/**
 * 档案盒盒记录上报Controller
 *
 * @author 派大星
 * @date 2024-07-23
 */
@RestController
@RequestMapping("/archive/ArchiveBoxInoutRecords")
public class ArchiveBoxInoutRecordsController extends BaseController
{
    @Autowired
    private IArchiveBoxInoutRecordsService archiveBoxInoutRecordsService;
    @Autowired
    private IArchiveBoxInoutdetailService archiveBoxInoutdetailService;

    /**
     * 查询档案盒盒记录上报列表
     */
    @PreAuthorize("@ss.hasPermi('archive:ArchiveBoxInoutRecords:list')")
    @GetMapping("/list")
    public TableDataInfo list(ArchiveBoxInoutRecords archiveBoxInoutRecords)
    {
        startPage();
        List<ArchiveBoxInoutRecords> list = archiveBoxInoutRecordsService.selectArchiveBoxInoutRecordsList(archiveBoxInoutRecords);
        return getDataTable(list);
    }

    /**
     * 导出档案盒盒记录上报列表
     */
    @PreAuthorize("@ss.hasPermi('archive:ArchiveBoxInoutRecords:export')")
    @Log(title = "档案盒盒记录上报", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ArchiveBoxInoutRecords archiveBoxInoutRecords)
    {
        List<ArchiveBoxInoutRecords> list = archiveBoxInoutRecordsService.selectArchiveBoxInoutRecordsList(archiveBoxInoutRecords);
        for(ArchiveBoxInoutRecords archiveBoxInoutRecords1:list){
            List<ArchiveBoxInoutdetail> archiveBoxInoutdetailList = archiveBoxInoutdetailService.selectArchiveBoxInoutdetailList(new ArchiveBoxInoutdetail(){{setRecordId(archiveBoxInoutRecords1.getId());}});
            archiveBoxInoutRecords1.setBoxList(archiveBoxInoutdetailList);
        }
        ExcelUtil<ArchiveBoxInoutRecords> util = new ExcelUtil<ArchiveBoxInoutRecords>(ArchiveBoxInoutRecords.class);
        util.exportExcel(response, list, "档案盒盒记录上报数据");
    }

    /**
     * 获取档案盒盒记录上报详细信息
     */
    @PreAuthorize("@ss.hasPermi('archive:ArchiveBoxInoutRecords:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(archiveBoxInoutRecordsService.selectArchiveBoxInoutRecordsById(id));
    }

    /**
     * 新增档案盒盒记录上报
     */
    @PreAuthorize("@ss.hasPermi('archive:ArchiveBoxInoutRecords:add')")
    @Log(title = "档案盒盒记录上报", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ArchiveBoxInoutRecords archiveBoxInoutRecords)
    {
        return toAjax(archiveBoxInoutRecordsService.insertArchiveBoxInoutRecords(archiveBoxInoutRecords));
    }

    /**
     * 修改档案盒盒记录上报
     */
    @PreAuthorize("@ss.hasPermi('archive:ArchiveBoxInoutRecords:edit')")
    @Log(title = "档案盒盒记录上报", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ArchiveBoxInoutRecords archiveBoxInoutRecords)
    {
        return toAjax(archiveBoxInoutRecordsService.updateArchiveBoxInoutRecords(archiveBoxInoutRecords));
    }

    /**
     * 删除档案盒盒记录上报
     */
    @PreAuthorize("@ss.hasPermi('archive:ArchiveBoxInoutRecords:remove')")
    @Log(title = "档案盒盒记录上报", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(archiveBoxInoutRecordsService.deleteArchiveBoxInoutRecordsByIds(ids));
    }
}
